package com.example.springbootmvc.contoller;


import com.example.springbootmvc.annotation.KVAutowired;
import com.example.springbootmvc.annotation.KVController;
import com.example.springbootmvc.annotation.KVRequestMapping;
import com.example.springbootmvc.annotation.KVRequestParam;
import com.example.springbootmvc.service.IDemoService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@KVController
@KVRequestMapping("/demo")
public class DemoController {
    @KVAutowired
    IDemoService demoService;

    @KVRequestMapping("/query")
    public void query(HttpServletRequest request, HttpServletResponse response,@KVRequestParam("name") String name) throws IOException {
        String result = demoService.get(name);
        response.getWriter().write(result);
    }

    @KVRequestMapping("/add")
    public void add(HttpServletRequest request, HttpServletResponse response,@KVRequestParam("a") Integer a,@KVRequestParam("b")Integer b) throws IOException {

        response.getWriter().write(a + "+" + b + "=" + (a + b));
    }
}
